package com.hanlp.bean;

import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 通用API响应封装类
 *
 * @param <T> 数据类型
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ApiResponse<T> {
    private String version;
    private T result;
    private boolean success;
    private String message;
    private int code;

    public ApiResponse(boolean success, String message, int code) {
        this.success = success;
        this.message = message;
        this.code = code;
    }

    public ApiResponse(boolean success, String message, int code, T result) {
        this.success = success;
        this.message = message;
        this.code = code;
        this.result = result;
    }

    /**
     * 创建成功响应
     */
    public static <T> ApiResponse<T> success(T data, String message) {
        return new ApiResponse<>(true, message, 200, data);
    }

    /**
     * 创建错误响应
     */
    public static <T> ApiResponse<T> error(String message) {
        return new ApiResponse<>(false, message, 500);
    }

    /**
     * 分页结果封装类
     *
     * @param <T> 数据类型
     */
    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class PageResult<T> {
        private int pages;
        private List<T> data;
        private int count;
    }
}